﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Web.Hosting;
using WeiSha.Core.Param.Method;

namespace WeiSha.Core
{
	// Token: 0x02000006 RID: 6
	public class LBS
	{
		// Token: 0x1700000F RID: 15
		// (get) Token: 0x0600002E RID: 46 RVA: 0x00002E04 File Offset: 0x00001004
		public static LBS Get
		{
			get
			{
				return LBS._get;
			}
		}

		// Token: 0x17000010 RID: 16
		// (get) Token: 0x0600002F RID: 47 RVA: 0x00002E1C File Offset: 0x0000101C
		public static bool Enable
		{
			get
			{
				bool flag = LBS._enable == null;
				if (flag)
				{
					PlatformInfoHandler.SiteInfoHandlerParaNode siteInfoHandlerParaNode = PlatformInfoHandler.Node("LBS");
					LBS._enable = ((siteInfoHandlerParaNode != null) ? siteInfoHandlerParaNode.AttrValue("enable").Boolean : new bool?(false));
					string @string = LBS.Get["BaiduAK"].String;
					bool flag2 = string.IsNullOrWhiteSpace(@string);
					if (flag2)
					{
						LBS._enable = new bool?(false);
					}
				}
				return LBS._enable.Value;
			}
		}

		// Token: 0x06000030 RID: 48 RVA: 0x00002EA2 File Offset: 0x000010A2
		private LBS()
		{
		}

		// Token: 0x17000011 RID: 17
		public ConvertToAnyValue this[string key]
		{
			get
			{
				return new ConvertToAnyValue(PlatformInfoHandler.Node("LBS").ItemValue(key));
			}
		}

		// Token: 0x06000032 RID: 50 RVA: 0x00002ED4 File Offset: 0x000010D4
		public static string Attr(string key)
		{
			PlatformInfoHandler.SiteInfoHandlerParaNode siteInfoHandlerParaNode = PlatformInfoHandler.Node("LBS");
			return (siteInfoHandlerParaNode != null) ? siteInfoHandlerParaNode.Attribute(key) : string.Empty;
		}

		// Token: 0x17000012 RID: 18
		// (get) Token: 0x06000033 RID: 51 RVA: 0x00002F04 File Offset: 0x00001104
		public static Dictionary<int, string> Areas
		{
			get
			{
				object @lock = LBS._lock;
				Dictionary<int, string> areas;
				lock (@lock)
				{
					bool flag2 = LBS._areas.Count < 1;
					if (flag2)
					{
						string text = HostingEnvironment.MapPath("~/Utilities/AreaCodeInfo.csv");
						try
						{
							using (StreamReader streamReader = new StreamReader(text, Encoding.UTF8))
							{
								string text2;
								while ((text2 = streamReader.ReadLine()) != null)
								{
									text2 = text2.Trim();
									bool flag3 = string.IsNullOrWhiteSpace(text2);
									if (!flag3)
									{
										bool flag4 = text2.IndexOf(",") < 0;
										if (!flag4)
										{
											int num;
											int.TryParse(text2.Substring(0, text2.IndexOf(",")), out num);
											bool flag5 = !LBS._areas.ContainsKey(num);
											if (flag5)
											{
												LBS._areas.Add(num, text2.Substring(text2.IndexOf(",") + 1));
											}
										}
									}
								}
							}
						}
						catch
						{
						}
					}
					areas = LBS._areas;
				}
				return areas;
			}
		}

		// Token: 0x06000034 RID: 52 RVA: 0x0000304C File Offset: 0x0000124C
		public static Dictionary<int, string> Provinces()
		{
			Dictionary<int, string> dictionary = new Dictionary<int, string>();
			foreach (KeyValuePair<int, string> keyValuePair in LBS.Areas)
			{
				bool flag = keyValuePair.Key % 10000 > 0;
				if (!flag)
				{
					dictionary.Add(keyValuePair.Key, keyValuePair.Value);
				}
			}
			return dictionary;
		}

		// Token: 0x06000035 RID: 53 RVA: 0x000030D4 File Offset: 0x000012D4
		public static Dictionary<int, string> Cities(int province)
		{
			while (province > 99)
			{
				province /= 10;
			}
			Dictionary<int, string> dictionary = new Dictionary<int, string>();
			foreach (KeyValuePair<int, string> keyValuePair in LBS.Areas)
			{
				bool flag = keyValuePair.Key / 10000 != province;
				if (!flag)
				{
					bool flag2 = keyValuePair.Key % 10000 == 0;
					if (!flag2)
					{
						bool flag3 = keyValuePair.Key % 100 != 0;
						if (!flag3)
						{
							dictionary.Add(keyValuePair.Key, keyValuePair.Value);
						}
					}
				}
			}
			bool flag4 = dictionary.Count < 1;
			if (flag4)
			{
				foreach (KeyValuePair<int, string> keyValuePair2 in LBS.Areas)
				{
					bool flag5 = keyValuePair2.Key / 10000 != province;
					if (!flag5)
					{
						bool flag6 = keyValuePair2.Key % 10000 == 0;
						if (!flag6)
						{
							dictionary.Add(keyValuePair2.Key, keyValuePair2.Value);
						}
					}
				}
			}
			return dictionary;
		}

		// Token: 0x06000036 RID: 54 RVA: 0x00003238 File Offset: 0x00001438
		public static Dictionary<int, string> Cities(string province)
		{
			int code = LBS.GetCode(province);
			return LBS.Cities(code);
		}

		// Token: 0x06000037 RID: 55 RVA: 0x00003258 File Offset: 0x00001458
		public static Dictionary<int, string> Districts(int city)
		{
			while (city > 9999)
			{
				city /= 10;
			}
			Dictionary<int, string> dictionary = new Dictionary<int, string>();
			foreach (KeyValuePair<int, string> keyValuePair in LBS.Areas)
			{
				bool flag = keyValuePair.Key / 100 != city;
				if (!flag)
				{
					bool flag2 = keyValuePair.Key % 100 == 0;
					if (!flag2)
					{
						dictionary.Add(keyValuePair.Key, keyValuePair.Value);
					}
				}
			}
			return dictionary;
		}

		// Token: 0x06000038 RID: 56 RVA: 0x0000330C File Offset: 0x0000150C
		public static Dictionary<int, string> Districts(string city)
		{
			int code = LBS.GetCode(city);
			bool flag = code % 1000 == 0;
			Dictionary<int, string> dictionary;
			if (flag)
			{
				dictionary = LBS.Cities(code);
			}
			else
			{
				dictionary = LBS.Districts(code);
			}
			return dictionary;
		}

		// Token: 0x06000039 RID: 57 RVA: 0x00003344 File Offset: 0x00001544
		public static int GetCode(string name)
		{
			foreach (KeyValuePair<int, string> keyValuePair in LBS.Areas)
			{
				bool flag = keyValuePair.Value.Equals(name);
				if (flag)
				{
					return keyValuePair.Key;
				}
			}
			return -1;
		}

		// Token: 0x0600003A RID: 58 RVA: 0x000033B4 File Offset: 0x000015B4
		public static string GetArea(int code)
		{
			while (code.ToString().Length < 6)
			{
				code *= 10;
			}
			while (code.ToString().Length > 6)
			{
				code /= 10;
			}
			foreach (KeyValuePair<int, string> keyValuePair in LBS.Areas)
			{
				bool flag = keyValuePair.Key == code;
				if (flag)
				{
					return keyValuePair.Value;
				}
			}
			return string.Empty;
		}

		// Token: 0x0600003B RID: 59 RVA: 0x00003460 File Offset: 0x00001660
		public static string GetArea(string code)
		{
			bool flag = string.IsNullOrWhiteSpace(code);
			string text;
			if (flag)
			{
				text = string.Empty;
			}
			else
			{
				bool flag2 = code.Length > 6;
				if (flag2)
				{
					code = code.Substring(0, 6);
				}
				int num;
				int.TryParse(code, out num);
				text = LBS.GetArea(num);
			}
			return text;
		}

		// Token: 0x04000010 RID: 16
		private static readonly LBS _get = new LBS();

		// Token: 0x04000011 RID: 17
		private static bool? _enable = null;

		// Token: 0x04000012 RID: 18
		private static readonly Dictionary<int, string> _areas = new Dictionary<int, string>();

		// Token: 0x04000013 RID: 19
		private static readonly object _lock = new object();
	}
}
